home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacWorld 1998 March
/
Macworld (1998-03) (Disk 1).dmg
/
Shareware World
/
Info
/
For Developers
/
GhostScript 5.10
/
MacGS-510
/
files
/
gs_cmap.ps
< prev
next >
Wrap
Text File
|
1997-06-11
|
8KB
|
243 lines
% Copyright (C) 1995, 1996, 1997 Aladdin Enterprises. All rights reserved.
%
% This file is part of Aladdin Ghostscript.
%
% Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author
% or distributor accepts any responsibility for the consequences of using it,
% or for whether it serves any particular purpose or works at all, unless he
% or she says so in writing. Refer to the Aladdin Ghostscript Free Public
% License (the "License") for full details.
%
% Every copy of Aladdin Ghostscript must include a copy of the License,
% normally in a plain ASCII text file named PUBLIC. The License grants you
% the right to copy, modify and redistribute Aladdin Ghostscript, but only
% under certain conditions described in the License. Among other things, the
% License requires that the copyright notice and this notice be preserved on
% all copies.
% ProcSet for implementing CMap resources.
% When this is run, systemdict is still writable.
% NOTE: Rearranged fonts are not implemented yet.
% ---------------- Public operators ---------------- %
% composefont doesn't appear in CMap files -- it's documented in
% the "PostScript Language Reference Manual Supplement".
/composefont % <name> <cmap|cmapname> <fonts> composefont <font>
{ 10 dict begin
1 index dup type /dicttype ne { /CMap findresource } if
/CMap exch def
/Encoding [ 0 1 4 index length 1 sub { } for ] def
/FDepVector 1 index def
/FMapType 9 def
/FontMatrix matrix def
/FontName 3 index def
/CMap load /WMode .knownget { /WMode exch def } if
/FontType 0 def
pop pop currentdict end /Font defineresource
} bind odef
% ---------------- CMap operators ---------------- %
30 dict begin
% Our internal .CodeMaps structure is an array of two arrays: array 0
% is the map for defined characters, array 1 is the map for notdefs.
% Both are multi-level arrays indexed by the successive bytes of the
% character code. Each value is either a sub-array, null, a character name,
% a CID (an integer), or a character code (expressed as a byte string).
% All of the arrays are read-only after they have been built.
%
% Note that the code in zfcmap.c that constructs the C structures from
% the PostScript structures has intimate knowledge of the above format.
/.getmap { .CodeMaps exch get } bind def
/.putmap { .CodeMaps exch 3 -1 roll put } bind def
% ------ Font-level operators ------ %
/begincmap % - begincmap -
{ /.CodeMaps [256 array 256 array] def
} bind def
/endcmap % - endcmap -
{ /.CodeMaps .CodeMaps .endmap def
/CodeMap null def % for .buildcmap
currentdict end .buildcmap begin
} bind def
/begincodespacerange % <count> begincodespacerange -
{ pop mark
} bind def
/endcodespacerange % <code_lo> <code_hi> ... endcodespacerange -
{ counttomark 2 idiv
{ .CodeMaps { 3 copy .addcodespacerange pop } forall pop pop
} repeat pop
} bind def
/.addcodespacerange % <code_lo> <code_hi> <map> .addcodespacerange -
{ 2 index length 1 eq
{ 2 { 3 -1 roll 0 get } repeat 1 exch
{ 2 copy 0 put pop } for pop
}
{ 2 index 0 get 1 3 index 0 get
6 -2 roll
2 { 1 1 index length 1 sub getinterval 6 1 roll } repeat
% Stack: lo hi map lo0 1 hi0
{ 2 copy get null eq { 2 copy 256 array put } if
4 copy get .addcodespacerange pop
}
for pop pop pop
}
ifelse
} bind def
/.endmap % <map> .endmap <map>
{ dup type /arraytype eq { dup { .endmap exch } forall astore readonly } if
} bind def
/usecmap % <CMap_name> usecmap -
{ /CMap findresource
dup length dict .copydict
currentdict end exch .copydict begin
} bind def
% ------ Rearranged font operators ------ %
/beginrearrangedfont % <font_name> <font*> beginrearrangedfont -
{ (NOT IMPLEMENTED YET.\n) print flush
} bind def
/endrearrangedfont % - endrearrangedfont -
{ (NOT IMPLEMENTED YET.\n) print flush
} bind def
/usefont % <fontID> usefont -
{ (NOT IMPLEMENTED YET.\n) print flush
} bind def
/beginusematrix % <fontID> beginusematrix -
{ (NOT IMPLEMENTED YET.\n) print flush
} bind def
/endusematrix % <matrix> endusematrix -
{ (NOT IMPLEMENTED YET.\n) print flush
} bind def
% ------ Character name/code selector operators ------ %
/beginbfchar % <count> beginbfchar -
{ pop mark
} bind def
/endbfchar % <code> <to_code|charname> ... endbfchar
{ 0 .getmap .endmapchar 0 .putmap
} bind def
/beginbfrange % <count> beginbfrange -
{ pop mark
} bind def
/endbfrange % <code_lo> <code_hi> <to_code|(charname*)> ...
% endbfrange -
{ 0 .getmap counttomark 3 idiv { .addbfrange } repeat 0 .putmap pop
} bind def
/.addbfrange % <code_lo> <code_hi> <to_code|(charname*)> <map>
% .addbfrange <map>
{ 1 index type /stringtype eq
{ { dup length string copy dup dup length 1 sub 2 copy get 1 add put }
exch .addmaprange
}
{ 2 dict begin exch /codes 1 index def 0 get exch
{ codes dup length 1 sub 1 exch getinterval /codes 1 index def
dup length 0 gt { 0 get } if
}
exch .addmaprange end
}
ifelse exch pop
} bind def
% ------ CID selector operators ------ %
/begincidchar % <count> begincidchar -
{ pop mark
} bind def
/endcidchar % <code> <cid> ... endcidchar -
{ 0 .getmap .endmapchar 0 .putmap
} bind def
/begincidrange % <count> begincidrange -
{ pop mark
} bind def
/endcidrange % <code_lo> <code_hi> <cid_base> ... endcidrange -
{ 0 .getmap counttomark 3 idiv { { 1 add } exch .addmaprange exch pop } repeat
0 .putmap pop
} bind def
/.endmapchar % -mark- <code> <value> ... <map> .endmapchar -
{ counttomark 2 idiv
{ 2 index 3 1 roll { } exch .addmaprange exch pop
} repeat exch pop
} bind def
/.addmaprange % <code_lo> <code_hi> <value_base> <next_proc> <map>
% .addcidrange <value_next> <map>
{ % We may be updating a (partly) read-only map from another CMap.
% If so, implement copy-on-write.
dup wcheck not { dup length array copy } if
4 index length 1 eq
{ 2 { 5 -1 roll 0 get } repeat 1 exch
{ % Stack: value proc map code
2 copy 5 index put pop
3 -1 roll 2 index exec 3 1 roll
} for
}
{ 4 index 0 get 1 5 index 0 get
8 -2 roll
2 { 1 1 index length 1 sub getinterval 8 1 roll } repeat
% Stack: lo hi next proc map lo0 1 hi0
{ 6 copy get .addmaprange
% Stack: lo hi oldnext proc map i next submap
exch 6 1 roll 5 -1 roll pop
% Stack: lo hi next proc map i submap
3 copy put pop pop
}
for 5 -2 roll pop pop
}
ifelse exch pop
} bind def
% ------ notdef operators ------ %
/beginnotdefchar % <count> beginnotdefchar -
{ pop mark
} bind def
/endnotdefchar % <code> <cid> ... endnotdefchar -
{ counttomark 2 idiv { 1 index exch .addnotdefrange } repeat pop
} bind def
/beginnotdefrange % <count> beginnotdefrange -
{ pop mark
} bind def
/endnotdefrange % <code_lo> <code_hi> <cid> ... endnotdefrange -
{ counttomark 3 idiv { .addnotdefrange } repeat pop
} bind def
/.addnotdefrange % <code_lo> <code_hi> <cid_base> .addnotdefrange -
{ { } 1 .getmap .addmaprange 1 .putmap pop
} bind def
% ---------------- Resource category definition ---------------- %
currentdict end
languagelevel exch 2 .setlanguagelevel
/CMap /Generic /Category findresource dup length dict .copydict
/Category defineresource pop
% We might have loaded CID font support already.
/CIDInit /ProcSet 2 copy { findresource } .internalstopped
% An interior `stopped' might have reset VM allocation to local.
true .setglobal
{ pop pop 3 -1 roll }
{ dup length 4 index length add dict .copydict 4 -1 roll exch .copydict }
ifelse exch defineresource pop
.setlanguagelevel